
#include "CGameApplication.h"
#include "Timer.h"

Timer::Timer()
{
	startTicks = pausedTicks = 0;
    paused = started = false;
}

void Timer::start()
{
    started = true;
    paused = false;

    startTicks = SDL_GetTicks();
}

void Timer::stop()
{
    started = paused = false;
}

void Timer::delay()
{
	if( this->getTicks() < 1000 / FRAMES_PER_SECOND )
	{
		SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - this->getTicks() );
	}
}

int Timer::getTicks()
{
    if( started == true )
    {
        if( paused == true )
        {
            return pausedTicks;
        }
        else
        {
            return SDL_GetTicks() - startTicks;
        }
    }

    return 0;
}